package com.java235;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

public class ListDemo {
    public static void main(String[] args) {
        // 创建集合对象
        ArrayList<String> arrList = new ArrayList<String>();

        arrList.add("张三");
        arrList.add("李四");
        arrList.add("王五");

        // 遍历
//        for (String s : arrList) {
//            System.out.println(s);
//        }

//        Iterator<String> it = arrList.iterator();
//        while(it.hasNext()) {
//            String s = it.next();
//            System.out.println(s);
//        }

        for (int i = 0; i < arrList.size(); i++) {
            String s = arrList.get(i);
            System.out.println(s);
        }
        System.out.println("----------------------");
        // LinkedList
        LinkedList<String> linkedList = new LinkedList<String>();
        linkedList.add("张三");
        linkedList.add("李四");
        linkedList.add("王五");

        // 遍历
//        for (String s : linkedList) {
//            System.out.println(s);
//        }

//        Iterator<String> it = linkedList.iterator();
//        while(it.hasNext()) {
//            String s = it.next();
//            System.out.println(s);
//        }

        for (int i = 0; i < linkedList.size(); i++) {
            String s = linkedList.get(i);
            System.out.println(s);
        }
    }
}
